package com.mwy.springbootrabbitmq.amqp;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class Sender {

    private final static String EXCHANGE_NAME = "topic_exchange";


    //注入rabbitmq模板
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(String message){
        /**
         * 通过rabbitmq模板发送消息
         *  1.交换机名字
         *  2.routingKey
         *  3.消息内容
         */
        rabbitTemplate.convertAndSend(EXCHANGE_NAME,"a.orange",message);
    }

    public void sendFanout(String message){
        /**
         * 通过rabbitmq模板发送消息
         *  1.交换机名字
         *  2.routingKey
         *  3.消息内容
         */
        rabbitTemplate.convertAndSend("fanout_exchange","",message);
    }
}
